package com.yc.spring.bank;

import com.yc.spring.bank.bean.Account;
import com.yc.spring.bank.dao.AccountDao;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.annotation.Resource;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "web.FindServlet", value = "/findAccount")
public class webFindServlet extends HttpServlet {

    @Resource
    AccountDao accountDao;
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext servletContext = request.getServletContext();
        WebApplicationContext springContent =
                WebApplicationContextUtils.getWebApplicationContext(servletContext);
        AccountDao accountDao = springContent.getBean(AccountDao.class);
        String id = request.getParameter("id");
        Account account = accountDao.selectById(id);
        response.getWriter().append(account.toString());
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
